package com.iflytek.uoamp.agent.monitor.find;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;

import com.iflytek.uoamp.agent.common.util.ReadFileByLine;
import com.iflytek.uoamp.agent.core.sender.monitorsender.responseObj.Program;

/**
 * @author gaowei
 * 判定是否信任;如果信任则会默认开启监控;
 */
public class TrustJudgement {
	
	private String path;
	private Set<String> set = Collections.synchronizedSet(new HashSet<String>()); 
	
	public TrustJudgement(String path){
		this.path = path;
	}
	
	public void init(){
		Logger.getRootLogger().info("init trust and path = "+path);
		
		List<String> line = ReadFileByLine.getAllLine2Array(path, "utf-8", 0, -1);
		for(String cur:line){
			Logger.getRootLogger().info("add trust "+cur);
			set.add(cur);
		}
	}
	
	public void reSet(){
		set.clear();
		init();
	}
	
	public double canTrust(Program program){
		Logger.getRootLogger().info(program.getCpname()+" "+set.contains(program.getCpname()));
		if(set.contains(program.getCpname())){
			return 1;
		}
		return 0;
	}

}
